package com.hou.postgresql.blog.controller;


import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.hou.postgresql.blog.entity.po.BlogUser;
import com.hou.postgresql.blog.service.IBlogUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 侯征
 * @since 2020-05-22
 */
@Api(tags = "用户相关")
@RestController
@RequestMapping("/blog/user")
@Slf4j
public class BlogUserController {

    @Autowired
    IBlogUserService iBlogUserService;

    @ApiOperation("用户列表")
    @GetMapping("list")
    public List<BlogUser> list(){
        return iBlogUserService.list();
    }


    @ApiOperation("新增用户")
    @PostMapping("add")
    public Boolean add(@RequestBody BlogUser blogUser){
        return iBlogUserService.save(blogUser);
    }

    @ApiOperation("更新用户")
    @PutMapping("update")
    public Boolean update(@RequestBody BlogUser blogUser){
        return iBlogUserService.update(blogUser, Wrappers.<BlogUser>update().eq("id",blogUser.getId()));
    }

    @ApiOperation("详情")
    @GetMapping("detail")
    public BlogUser detail(Long id){
        return iBlogUserService.detail(id);
    }

}
